<%@ page contentType="text/html; charset=UTF-8"%>
<%@ include file="/jsp/common/common.jsp"%>
<html>
	<head>
		<script type="text/javascript" src="<%=contextPath%>/js/validator.js"></script> 
		<script type="text/javascript" src="<%=contextPath%>/js/jquery.autogrow.js"></script> 
		<script type="text/javascript" language="javascript">  
		
			Ext.onReady(function(){
			
				$('textarea').autogrow();
			
				var tb = new Ext.Toolbar({
			   		renderTo: document.all.tbar,
			    	items: [
				        {
				            text: '保存',
				            icon:"<%=contextPath%>/images/save.gif",
				            handler:toCheck,
				            hidden:<%=session.getAttribute("btn_save_display") != null || "1".equals(session.getAttribute("SESSION_ISADMIN")) ? false:true%>
				        },'-',
				        {
				            text: '返回',
				            icon:"<%=contextPath%>/images/fanhui.png",
				            handler:function(){
				            	back();
				            }
				        }
			    	]
			    });
			});
		  
			function toCheck(){

			  	if(!Validator.Validate(frmM,2)){
				  return false;
			  	}
			  	
			  	// 新建时
			  	if (document.frmM.elements["dic.id"].value == 0) {

					$.ajax({
						type: "post",
						url : "<%=contextPath%>/dic!check.do",
						dataType:'json',
						data: 'itemId=' + frmM.elements["dic.itemId"].value + "&itemType=" + frmM.elements["dic.itemType"].value,
						success: function(json,state){
	
							// 通过验证
							if (json.m == undefined) {
								$('#result').html("");
								// 提交
								comt();
							} else {
								alert(json.m);
								return;
							}
						},
						error:function(json) {
							alert("异步失败！");
						}
					});
					
					// 修改时
  				} else {
  				
  					comt();
  				}
		    }   

		 </script>  
	</head>
	<body>
		<div id = "tbar"></div>
		<center>
			<!-- 信息提示 -->
			<div result><font color="red">${info }</font></div>
		</center>
		<form id="frmM" class="ct" name="frmM" method="POST" action="<%=contextPath%>/dic!save.do">
			<s:hidden name="dic.id" />
			<s:hidden name="dic.itemType" />
			
			<table width="100%" id="infotab">
				<tr>
					<th class="rt" width="120" nowrap>字典类别：
					</th>
					<td>
						<input type="text" name="dic.itemValue" id="dic.itemValue" readonly="true"  size="25" value="${dic.itemValue}"/>
						
					</td>
				</tr>
				<tr>
					<th class="rt" width="120" nowrap>
						<font color="red">*</font>&nbsp;编号：
					</th>
					<td>
						<c:if test="${dic.id == '0'}">
							<input type="text" name="dic.itemId" id="dic.itemId" datatype="Require" maxlength="50" size="25" value="${dic.itemId}" msg="编号必须输入。"/>
						</c:if>
						<c:if test="${dic.id != '0'}">
							<input type="text" name="dic.itemId" id="dic.itemId" datatype="Require"  maxlength="50" size="25" value="${dic.itemId}" msg="编号必须输入。"/>
						</c:if>
					</td>
				</tr>
				<tr>
					<th class="rt" width="120" >
						<font color="red">*</font>&nbsp;名称：
					</th>
					<td nowrap>

						<input type="text" name="dic.itemName" datatype="Require" maxlength="50" size="25" value="${dic.itemName}" msg="名称必须输入。"/>

					</td>
				</tr>
				
				<tr>
					<th class="rt" width="120" nowrap>
						备注：
					</th>
					<td>
						<textarea name="dic.remark" style="width:98%; height: 30px; min-height: 20px;line-height:15pt"  min="0" max="1000" datatype="LimitB" rows="4" cols="60" msg="备注最大输入100个汉字或者200个字符。">${dic.remark}</textarea>
					</td>
				</tr>
			</table>
		</form>
	</body>
</html>
<script language="javascript">

	 // 保存
     function comt(){
     	document.frmM.action = "<%=contextPath%>/dic!save.do";
     	document.frmM.submit();
     }
     
     // 返回
     function back() {
     	document.frmM.action = "<%=contextPath%>/dicList!getList.do";
		document.frmM.submit();
     }

	 // 查询
	 function cmt(){
		document.frmM.action = "<%=contextPath%>/dicList!getList.do?page=1";
		document.frmM.submit();
	 }
</script>